function Product(jsonObject) {
	this.internalObject = jsonObject;
}

Product.prototype = {
	getCategoryId: function() { return this.internalObject.CategoryId; },
	setCategoryId: function(categoryid) { this.internalObject.CategoryId = categoryid; },
	getDiscontinued: function() { return this.internalObject.Discontinued; },
	setDiscontinued: function(discontinued) { this.internalObject.Discontinued = discontinued; },
	getProductId: function() { return this.internalObject.ProductId; },
	getProductName: function() { return this.internalObject.ProductName; },
	setProductName: function(productname) { this.internalObject.ProductName = productname; },
	getQuantityPerUnit: function() { return this.internalObject.QuantityPerUnit; },
	setQuantityPerUnit: function(quantityperunit) { this.internalObject.QuantityPerUnit = quantityperunit; },
	getReorderLevel: function() { return this.internalObject.ReorderLevel; },
	setReorderLevel: function(reorderlevel) { this.internalObject.ReorderLevel = reorderlevel; },
	getSupplierId: function() { return this.internalObject.SupplierId; },
	setSupplierId: function(supplierid) { this.internalObject.SupplierId = supplierid; },
	getUnitPrice: function() { return this.internalObject.UnitPrice; },
	setUnitPrice: function(unitprice) { this.internalObject.UnitPrice = unitprice; },
	getUnitsInStock: function() { return this.internalObject.UnitsInStock; },
	setUnitsInStock: function(unitsinstock) { this.internalObject.UnitsInStock = unitsinstock; },
	getUnitsOnOrder: function() { return this.internalObject.UnitsOnOrder; },
	setUnitsOnOrder: function(unitsonorder) { this.internalObject.UnitsOnOrder = unitsonorder; },
	getCreatedDate: function() { return this.internalObject.CreatedDate; },
	getCreatedBy: function() { return this.internalObject.CreatedBy; },
	getModifiedDate: function() { return this.internalObject.ModifiedDate; },
	getModifiedBy: function() { return this.internalObject.ModifiedBy; },
	getProductObject: function() { return this.internalObject; }
};

function ProductService() {
}

ProductService.prototype.retrieveAll = function(successCallback) {
    viewServiceProxy.invokeGet("ProductList", successCallback, OnPageError, true);
};

ProductService.prototype.retrievePaged = function(successCallback, pageIndex, pageSize, sortOrder, sortColumn, linq) {
    var restUrl = "ProductListPage";
    restUrl = restUrl + "/?";

    if (!IsNullOrEmpty(pageIndex)) {
        restUrl = restUrl + "pageIndex=" + pageIndex;
        if (!IsNullOrEmpty(pageSize) || !IsNullOrEmpty(sortOrder) || !IsNullOrEmpty(sortColumn) || !IsNullOrEmpty(linq)) {
            restUrl = restUrl + "&";
        }
    }
    if (!IsNullOrEmpty(pageSize)) {
        restUrl = restUrl + "pageSize=" + pageSize;
        if (!IsNullOrEmpty(sortOrder) || !IsNullOrEmpty(sortColumn) || !IsNullOrEmpty(linq)) {
            restUrl = restUrl + "&";
        }
    }
    if (!IsNullOrEmpty(sortOrder)) {
        restUrl = restUrl + "sortOrder=" + sortOrder;
        if (!IsNullOrEmpty(sortColumn) || !IsNullOrEmpty(linq)) {
            restUrl = restUrl + "&";
        }
    }
    if (!IsNullOrEmpty(sortColumn)) {
        restUrl = restUrl + "sortColumn=" + sortColumn;
        if (!IsNullOrEmpty(linq)) {
            restUrl = restUrl + "&";
        }
    }
    restUrl = restUrl + "linq=" + linq;

    viewServiceProxy.invokeGet(restUrl, successCallback, OnPageError, true);
};

ProductService.prototype.save = function(product, successCallback) {
viewServiceProxy.invokePut("Product", product.getProductObject(), successCallback, OnPageError, true);
};
